//
//  ZLW_RecommentCell.m
//  Otaku
//
//  Created by lanou3g on 16/5/5.
//  Copyright © 2016年 Liuwx. All rights reserved.
//

#import "ZLW_RecommentCell.h"

@interface ZLW_RecommentCell ()<UIAlertViewDelegate,UMSocialUIDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *avatar_url_iamge;
@property (weak, nonatomic) IBOutlet UILabel *Name;
@property (weak, nonatomic) IBOutlet UILabel *content;
@property (weak, nonatomic) IBOutlet UIImageView *urlImageView;
@property (weak, nonatomic) IBOutlet UIButton *categoryName;

@property (weak, nonatomic) IBOutlet UIButton *Good;
@property (weak, nonatomic) IBOutlet UIButton *Bad;

@property (weak, nonatomic) IBOutlet UIButton *comment_count;
@property (weak, nonatomic) IBOutlet UIButton *share_count;


@end


@implementation ZLW_RecommentCell

-(void)setGetmodel:(ZLW_RecommentModel *)getmodel
{
    if (_getmodel != getmodel) {
        _getmodel = getmodel;
    }
    
}

- (IBAction)GoodAction:(UIButton *)sender
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"add_one@3x" ofType:@"png"];
    UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
    UIImageView *imgView = [[UIImageView alloc]initWithImage:image];
    imgView.alpha = 1;
    [sender addSubview:imgView];
    
//        if (sender.selected) {
    
       [self.Good setTitle:[NSString stringWithFormat:@"%ld",(long)self.getmodel.digg_count+1] forState:(UIControlStateNormal)];
            [UIView animateWithDuration:1 animations:^{
            imgView.alpha = 0;
        } completion:^(BOOL finished) {
            [imgView removeFromSuperview];

        }];

//    }
//        else
//    {
//        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"" message:@"你已经选择" preferredStyle:(UIAlertControllerStyleAlert)];
//        [alertVC addAction:[UIAlertAction actionWithTitle:@"知道了" style:(UIAlertActionStyleDefault) handler:nil]];
//
//        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertVC animated:YES completion:nil];
//
//    }

   
}
- (IBAction)BadAction:(UIButton *)sender {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"add_one_night@3x" ofType:@"png"];
    UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
     UIImageView *imgView = [[UIImageView alloc]initWithImage:image];
    imgView.alpha = 1;
    [sender addSubview:imgView];
  
    if (sender.selected) {
        
        [UIView animateWithDuration:1 animations:^{
            imgView.alpha = 0;
        } completion:^(BOOL finished) {
            [imgView removeFromSuperview];
            [self.Bad setTitle:[NSString stringWithFormat:@"%ld",(long)self.getmodel.bury_count+1] forState:(UIControlStateNormal)];
            sender.enabled = NO;
        }];
    }else
    {
        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"" message:@"你已经选择" preferredStyle:(UIAlertControllerStyleAlert)];
        [alertVC addAction:[UIAlertAction actionWithTitle:@"知道了" style:(UIAlertActionStyleDefault) handler:nil]];
        
        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertVC animated:YES completion:nil];
           }
}

- (IBAction)category:(UIButton *)sender {
}

- (IBAction)share_url:(UIButton *)sender {
    NSURL *url = [NSURL URLWithString:self.getmodel.share_url];
    [[UIApplication sharedApplication] openURL:url];
}
- (IBAction)share:(UIButton *)sender {

    [UMSocialSnsService presentSnsIconSheetView:[UIApplication sharedApplication].keyWindow.rootViewController appKey:@"572c6a8ce0f55ac72d000352" shareText:self.getmodel.share_url
 shareImage:[UIImage imageNamed:@"icon"]shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToSina,UMShareToDouban,nil]delegate:self];

    [UMSocialData defaultData].extConfig.title = self.Name.text;
    [UMSocialData defaultData].shareText = [NSString stringWithFormat:@"%@+%@",self.Name.text,self.share_count.titleLabel.text];
  
}
-(void)layoutSubviews
{
    CGRect rect = self.urlImageView.frame;
    rect.size.height = MAXFLOAT;// 图片高度
    self.urlImageView.frame = rect;
    
  
    [self.avatar_url_iamge sd_setImageWithURL:[NSURL URLWithString:self.getmodel.avatar_url]];

    self.avatar_url_iamge.layer.cornerRadius = 15;
    self.Name.text = self.getmodel.name;
    self.content.text = self.getmodel.content;
   [self.urlImageView sd_setImageWithURL:[NSURL URLWithString:self.getmodel.url[@"url"]]];
   
   
    [self.categoryName setTitle:self.getmodel.category_name forState:(UIControlStateNormal)];
    
#pragma mark  点赞数目
    [self.Good setTitle:[NSString stringWithFormat:@"%ld",(long)self.getmodel.digg_count] forState:(UIControlStateNormal)];
    NSString *path1 = [[NSBundle mainBundle] pathForResource:@"digupicon_comment_press@3x" ofType:@"png"];
    UIImage *image1 = [[UIImage alloc] initWithContentsOfFile:path1];
    [self.Good setImage:image1  forState:(UIControlStateNormal)];

  
    

#pragma mark    不好数目
    [self.Bad setTitle:[NSString stringWithFormat:@"%ld",(long)self.getmodel.bury_count] forState:(UIControlStateNormal)];
    NSString *path2 = [[NSBundle mainBundle] pathForResource:@"digdownicon_textpage_press@3x" ofType:@"png"];
    UIImage *image2 = [[UIImage alloc] initWithContentsOfFile:path2];
    [self.Bad setImage:image2  forState:(UIControlStateNormal)];
#pragma mark 评论数目
    [self.comment_count setTitle:[NSString stringWithFormat:@"%ld",(long)self.getmodel.comment_count] forState:(UIControlStateNormal)];
    NSString *path3 = [[NSBundle mainBundle] pathForResource:@"commenticon_textpage_night@3x" ofType:@"png"];
    UIImage *image3 = [[UIImage alloc] initWithContentsOfFile:path3];
    [self.comment_count setImage:image3  forState:(UIControlStateNormal)];
# pragma amrk  分享数目
    [self.share_count setTitle:[NSString stringWithFormat:@"%ld",(long)self.getmodel.share_count] forState:(UIControlStateNormal)];
        NSString *path = [[NSBundle mainBundle] pathForResource:@"html_share_night@3x" ofType:@"png"];
    UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
    [self.share_count setImage:image  forState:(UIControlStateNormal)];
    

}

+ (CGFloat)heightModel:(ZLW_RecommentModel *)model
{

        CGFloat heightContent = [Tool labelHeightWithText:model.content font:[UIFont systemFontOfSize:17]];
        CGFloat heightUrliamge = [Tool imageScaleHeightWithImageUrl:model.url[@"url"] width:model.r_width height:model.r_height];
    
    return 150 + heightContent + heightUrliamge ;




}

- (void)awakeFromNib {
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
